package com.kdtech.analyse.Bbs.common;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.kdtech.analyse.AnalyseNews;
import com.kdtech.analyse.JSoupUtils;
import com.kdtech.crawler.CrawlHTML;
import com.kdtech.crawler.at.UrlArgumentTop;
import com.kdtech.entity.crawler.UrlMeta;
import com.kdtech.entity.data.AbstractMeta;
import com.kdtech.entity.data.NewsMeta;
import com.kdtech.utils.DateUtils;
import com.kdtech.utils.DoMainUtils;
import com.kdtech.utils.HtmlCleaner;
import com.kdtech.utils.NumberUtils;
import com.kdtech.utils.RegexUtils;
import com.kdtech.utils.StringUtils;
/**
 * Discuz! X2 X2.5 X3版本
 *
 * 0000
 * http://www.mycar168.net/ 麦卡车会
 * @author KK
 */
public class BbsAnalyseDiscuz implements AnalyseNews  {



	public BbsAnalyseDiscuz() {

		super();
	}


	public boolean isDetailPage(String url) {
		if(url.contains("channel") && url.contains("oeeee.com")){
			return false;
		}
		url = UrlArgumentTop.FromatUrl(url);
		System.out.println(url);
		if(url.endsWith("/")){
			url = url.substring(0,url.length()-1);
		}
		
		url = StringUtils.substringAfterLast(url, "/");
		if(url.startsWith("ztlist-")){return false;}
		if(url.startsWith("board")){return false;}
		
		String[] regex = {
				"thread-[0-9]*-1.html",
				"thread-[0-9]*-1-1.html",
				"[a-z]+-[0-9]*-1-1.html",
				"android-[0-9]*-1-1.html",
				"showtopic.aspx\\?topicid=[0-9]*",
				"viewthread.php\\?.*tid=[0-9]*.*",
				"forum.php\\?mod=viewthread&tid=[0-9]*",
				"forum.php\\?.*extra=(page%3D1)?&mod=viewthread(&page=1)?&tid=[0-9]*",
				"forum.php\\?tid=[0-9]*&mod=viewthread",
				//"[a-z]*-[0-9]*-1-1.html",
				"life-[0-9]*-1-1.html",
				"forum.php\\?extra=(page%3D1)?&tid=[0-9]*&mod=viewthread",
				"forum.php\\?extra=(page%3D1)?&mod=viewthread&tid=[0-9]*",
				"forum.php\\?mod=viewthread&tid=[0-9]*&extra=(page%3D1)?",
				"forum.php\\?.*mod=viewthread&tid=[0-9]+.*",
				"forum.php\\?extra=&mod=viewthread&tid=[0-9]*",
				"forum.php\\?fid=[0-9]*&mod=viewthread&tid=[0-9]*",
				"forum.php\\?mod=viewthread&page=1&tid=[0-9]*",
				"community-[0-9]*-1-1.html",
				"[0-9]{5,}-1-1.html",
				"[0-9]{5,}-1.html",
				"view-[0-9]*-1-1.html",
				"dongxiang_thread-[0-9]*-1-1.html",
				"w[0-9]*-1-1",
				"topic[0-9]*p1r1.html",
				"forum.php\\?mod=viewthread&tid=[0-9].*",
				"forum-viewthread-tid-[0-9]*-.*.html",
				"thread-[0-9].*-1-1.html",
				"t[0-9]+",
				"tg[0-9]+",
				"showAnnounce_[0-9].*_[0-9].*_1_0.htm",
				"[0-9]*_1_1.shtml",
				"muzat-tema-[0-9].*-1-1.html",
//				"forum.php\\?goto=lastpost&mod=redirect&tid=[0-9].*",
				"read-html?-tid-[0-9]*.html",
                 "showthread.php\\?forumid=[0-9]*&threadid=[0-9]*",
                 "[a-zA-Z]+/t[0-9]+/",
                 "showtopic.aspx\\?forumpage=[0-9]*&topicid=[0-9]*",
                 "t[0-9]+p1",
                 "[0-9]{4,}.html",
                 "t-[0-9]+-1-1",
                 "bbs_view_id_[0-9]+",
                 "t[0-9]+-1-1.htm",
                 "forum-viewthread-tid-[0-9]+-extra-page%3D1%26orderby%3Ddateline.html",
                 "d[0-9]*",
                 "read.php\\?tid-[0-9]+.html",
                 "read.php\\?.*tid=[0-9]+",
                 "read-htm-tid-[0-9]+-1.html",
                 "topic.asp[?]boardid=[0-9]*&topicid=[0-9]*",
                 "article-[0-9]*-1.html",
                 "article_[0-9]*.html",
                 "t-[0-9]*-1.htm",
                 "portal.php\\?aid=[0-9]*&mod=view",
                 "showtopic-[0-9]*.(aspx|html)",
                 "viewthread-[0-9]*-1-1.html",
                 "p-[0-9]+-1",
                 "thread-[0-9]+-1-1.do",
                 "ws[0-9]+",
                 "clubThreadDetail-[0-9]+-1.html.*",
                 "forum-[0-9]+-thread-[0-9]+-1-1.html",
                 "bbs/forum.php?mod=viewthread&tid=[0-9]*&extra=page%3D1",
                 "forum.php?mod=viewthread&tid=[0-9]*&extra=page%3D1",
                 "bbs/forum.php?mod=viewthread&tid=[0-9]*&extra=page%3D1",
                 "forum.php?mod=viewthread&tid=[0-9]*&extra=page%3D1"
                 };
		return RegexUtils.matchAny(url, regex);
	}

	public NewsMeta parserHtml(UrlMeta urlMeta) {
		if (urlMeta.getHtml() == null) {
			return null;
		}
		String htmltxt = urlMeta.getHtml();
		String url = urlMeta.getUrl();

		String title = null;
		String content = null;
		Long date = null;
		Integer commnetNum = null;
		Integer clickNum = null;
		String updateUrl = url;
		String author=null;
		Document doc = Jsoup.parse(htmltxt);
		doc.select("div.wp.a_t").remove();
		Elements select2 = doc.select("td#bodytitle:contains(Database Error),h1:contains(Discuz! Database Error)");
		if(select2.size()>0){
			return null;
		}
		Elements select3 = doc.select("div#messagetext.alert_info:contains(本帖要求阅读权限高于)");
		if(select3.size()>0){
			return null;
		}
		NewsMeta news = new NewsMeta();
		doc.select("ignore_js_op").remove();
		doc.select("#fastpostform").remove();
		doc.select("i.pstatus").remove();
		doc.select("div.locked").remove();
		doc.select("dl.rate").remove();
		doc.select(".attach_nopermission").remove();
		doc.select("a:containsOwn(登录/注册后可看大�?)").remove();
		doc.select("#bdshare").remove();
		doc.select("span.tfilink:containsOwn(本文地址)").remove();
		doc.select("div.ptg.mbm.mtn").remove();
		if(StringUtils.isBlank(title)){
			Element first = doc.select("#thread_subject").first();
			if (first!=null){
				title = first.text();
			}
			if(StringUtils.isBlank(title)){
				title = doc.select("h1.read_h1").text();
				if(StringUtils.isBlank(title)){
					title = doc.select("a.ts_name").text();
					if (StringUtils.isBlank(title)) {
						title = doc.select("h1.title-cont").text();
					}
					if(StringUtils.isBlank(title)){
							title = doc.select("h1").text();
					}
				}
			}
		}

		if (title!=null){
			title = title.replace("[复制链接]", "");
		}


		Element firstDiv = doc.select("div#postlist > div[id^=post_]").first();
		if (firstDiv!=null){
			Element first2 = firstDiv.select("div.pi a.xw1").first();
			if(first2!=null){
				author = first2.text();
			}
			if(StringUtils.isBlank(author)){
				author = firstDiv.select("h3#groupida").text();
			}
			if(StringUtils.isBlank(author)){
				Element firstA = firstDiv.select("div.authi>a[href]").first();
				if (firstA!=null){author =firstA .text();}
			}
			if(StringUtils.isBlank(author)){
				Element firstA = firstDiv.select("div.authi a.nickname").first();
				if (firstA!=null){author =firstA .text();}
			}
			if(StringUtils.isBlank(author)){
				Element first = firstDiv.select(".user_name a.xw1").first();
				if (first!=null) {author = first.text();}
			}
			if(StringUtils.isBlank(author)){
				author = firstDiv.select("div.d_name").text();
			}
			if(StringUtils.isBlank(author)){
				author = firstDiv.select("div.authi a.xi2").text();
			}
			if(StringUtils.isBlank(author)){
				author = doc.select(".userbyName").text();
			}
			if(StringUtils.isBlank(author)){
				author = doc.select("div.topic_name").text();
			}
			date = DateUtils.matchDate(firstDiv.select("div.authi span[title]").attr("title"));
			if(date==null)
				date = DateUtils.matchDate(firstDiv.select("div.barr_post span[title]").attr("title"));
			if(date==null)
				date = DateUtils.matchDate(firstDiv.select("div.authi em:contains(发表�?)").text());


			firstDiv.select("td.t_f a").remove();
			content = HtmlCleaner.getContentHtml(url, firstDiv.select("td.t_f"));

			Elements element = firstDiv.select("div.pcb");
			element.select(".attach_nopermission,#reg_post,#bdshare,[style=display:none],.jiathis_*").remove();
			if(StringUtils.isBlank(content))
				content = HtmlCleaner.getContentHtml(url, element);
		}
		if(StringUtils.isBlank(title)){
			title = doc.select("div.cont-hd h1").text();
		}
		if(StringUtils.isBlank(title)){
			title = doc.select("span#thread_subject").text();
		}
		if(StringUtils.isBlank(title)){
			title = doc.select("div#threadtitle h2").text();
		}
		if(StringUtils.isBlank(title)){
			title = doc.select("div.viewthread_sub h2").text();
		}
		if(StringUtils.isBlank(title)){
			title = doc.select("div.mainbox h3").text();
		}
		if(StringUtils.isBlank(title)){
			title = doc.select("td.bold span").text();
		}
		if(StringUtils.isBlank(title)){
			title = doc.select("div.bbs-title").text();
		}
		if(StringUtils.isBlank(title)){
			title = doc.select("div.postcontent h4").text();
		}
		if(StringUtils.isBlank(title)){
			title = doc.select("span.bold").text();
		}
		if(StringUtils.isBlank(title)){
			title = doc.select("h1.f14").text();
		}
		if(StringUtils.isBlank(title)){
			title = doc.select("div#nav").text();
			if(title.indexOf(" » ")!=-1)
			{
				title = title.substring(title.lastIndexOf(" » ") + 3);
			}
		}
		if(StringUtils.isBlank(content)){
			 Element first3 = doc.select("div#read_tpc").first();
			 content = HtmlCleaner.getContentHtml(url, first3);
		}
		 if(StringUtils.isBlank(content)){
			Element first = doc.select("div.t_msgfont").first();
			content = HtmlCleaner.getContentHtml(url, first);
		 }
		if(StringUtils.isBlank(content)){
			Element first2 = doc.select(".pcb").first();
			content =HtmlCleaner.getContentHtml(url,  first2);
		}
		if(StringUtils.isBlank(content)){
			content = HtmlCleaner.getContentHtml(url, doc.select("div#firstpost"));
		}
		if(StringUtils.isBlank(content)){
			 Element first4 = doc.select("div.t_fsz").first();
			 content = HtmlCleaner.getContentHtml(url, first4);
		}
		if(StringUtils.isBlank(content)){
			Element first5 = doc.select(".html-data.bbs-con").first();
			content = HtmlCleaner.getContentHtml(url,first5);
		}
		if(StringUtils.isBlank(content)){
			Element first5 = doc.select(".thread-cont").first();
			content = HtmlCleaner.getContentHtml(url,first5);
		}
		if(StringUtils.isBlank(content)){
			content = HtmlCleaner.getContentHtml(url, doc.select("div.article-cont"));
		}
		if(StringUtils.isBlank(content)){
			content = HtmlCleaner.getContentHtml(url, doc.select("td.topic_c"));
		}
		if(StringUtils.isBlank(content)){
			content = HtmlCleaner.getContentHtml(url, doc.select("td.t_msgfont"));
		}
		if(StringUtils.isBlank(content)){
			content = HtmlCleaner.getContentHtml(url, doc.select("div#article"));
		}
		if(StringUtils.isBlank(content)){
			content = HtmlCleaner.getContentHtml(url, doc.select("td#article_content"));
		}
		if(StringUtils.isBlank(content)){
			content = HtmlCleaner.getContentHtml(url, doc.select("div.main-content"));
		}
		if(StringUtils.isBlank(content)){
			content = HtmlCleaner.getContentHtml(url, doc.select("div.message"));
		}
		if(StringUtils.isBlank(content)){
			content = HtmlCleaner.getContentHtml(url, doc.select("div.cont"));
		}
		if(StringUtils.isBlank(content)){
			content = HtmlCleaner.getContentHtml(url, doc.select("div.postmessage"));
		}
		if(StringUtils.isBlank(content)){
			content = HtmlCleaner.getContentHtml(url, doc.select("td.content"));
		}
		if(StringUtils.isBlank(content)){
			content = HtmlCleaner.getContentHtml(url, doc.select("div.thread-cont"));
		}

		if(date==null){
			date = DateUtils.matchDate(doc.select("div.posts_info span[title]").attr("title"));
		}
		if(date==null){
			date = DateUtils.matchDate(doc.select("div.postinfo span[title]").attr("title"));
		}
		if(date==null){
			date = DateUtils.matchDate(doc.select("td#td_tpc.floot_right div.tipTop span").attr("title"));
		}
		if(date==null){
			date = DateUtils.matchDate(doc.select("td.plc div.po,div.cont-hd span:contains(发表�?)").text());
		}
		if(date==null){
			date = DateUtils.matchDate(doc.select("div.subject>em").text());
		}
		if(date==null){
			date = DateUtils.matchDate(doc.select("div.posts_info").text());
		}
		if(date==null){
			date = DateUtils.matchDate(doc.select("div.postinfo").text());
		}
		if (date==null){
			date = DateUtils.matchDate(doc.select("p.xg1").text());
		}
		if(date==null){
			date = DateUtils.matchDate(doc.select("div.t_msg span").text());
		}
		if (date==null){
			date = DateUtils.matchDate(doc.select(".authi").text());
		}
		if (date==null){
			date = DateUtils.matchDate(doc.select("div.s6").text());
		}
		if(date==null){
			date = DateUtils.matchDate(doc.select("span.time_sx").text());
		}
		if(date==null){
			date = DateUtils.matchDate(doc.select("div.main-info").text());
		}
		if(date==null){
			date = DateUtils.matchDate(doc.select("div.cont-tip").text());
		}
		if(date==null){
			date = DateUtils.matchDate(doc.select("p.postlinks").text());
		}
		if(date==null){
			date = DateUtils.matchDate(doc.select("ul.cont-top-left").text());
		}
		if(date==null){
			date =JSoupUtils.matchDate(doc, "查看","回复","阅读","发表�?", "发布日期", "上传日期");
		}

		if(StringUtils.isBlank(author)){
			Elements authorList = doc.select("a.post-user-name");
			if(authorList.size()>0)
			{
				author = authorList.get(0).text();
			}
		}

		String commTxt ="";
		if (clickNum == null && commnetNum==null ){
			commTxt = doc.select("div.eis_hm").text();
			clickNum = NumberUtils.matchNumber(StringUtils.substringAfter(commTxt, "查看"));
			commnetNum = NumberUtils.matchNumber(StringUtils.substringAfter(commTxt, "回复"));
		}
		if (clickNum == null && commnetNum==null ){
			commTxt = doc.select(".hm").text();
			clickNum = NumberUtils.matchNumber(StringUtils.substringAfter(commTxt, "查看"));
			commnetNum = NumberUtils.matchNumber(StringUtils.substringAfter(commTxt, "回复"));
			if (clickNum == null && commnetNum==null ){
				clickNum = NumberUtils.matchNumber(StringUtils.substringBefore(commTxt, "|"));
				commnetNum = NumberUtils.matchNumber(StringUtils.substringAfter(commTxt, "|"));
			}
		}
		if (clickNum == null && commnetNum==null ){
			commTxt = doc.select("span.popularity").text();
			clickNum = NumberUtils.matchNumber(StringUtils.substringBefore(commTxt, "|"));
			commnetNum = NumberUtils.matchNumber(StringUtils.substringAfter(commTxt, "|"));
		}

		if (clickNum == null && commnetNum==null ){
			commTxt = doc.select("div.posts_info").text();
			clickNum = NumberUtils.matchNumber(StringUtils.substringBefore(commTxt, "回复:"));
			commnetNum = NumberUtils.matchNumber(StringUtils.substringAfter(commTxt, "回复:"));
		}
		if (clickNum == null && commnetNum==null ){
			commTxt = doc.select("h1 div.y").text();
			clickNum = NumberUtils.matchNumber(StringUtils.substringAfter(commTxt, "�?"));
			commnetNum = NumberUtils.matchNumber(StringUtils.substringBefore(commTxt, "�?"));
		}
		if (clickNum == null && commnetNum==null ){
			commTxt = doc.select("div.singse_vtvs").text();
			clickNum = NumberUtils.matchNumber(StringUtils.substringBefore(commTxt, "查看"));
			commnetNum = NumberUtils.matchNumber(StringUtils.substringAfter(commTxt, "查看"));
		}
		if (clickNum == null && commnetNum==null ){
			commTxt = doc.select("div.hm").text();
			clickNum = NumberUtils.matchNumber(StringUtils.substringAfter(commTxt, "查看"));
			commnetNum = NumberUtils.matchNumber(StringUtils.substringAfter(commTxt, "回复"));
		}
		if (clickNum == null && commnetNum==null ){
			commTxt = doc.select("div.authi").text();
			clickNum = NumberUtils.matchNumber(StringUtils.substringAfter(commTxt, "查看"));
			commnetNum = NumberUtils.matchNumber(StringUtils.substringAfter(commTxt, "回复"));
		}
		if (clickNum == null && commnetNum==null ){
			commTxt = doc.select(".readNum").text();
			clickNum = NumberUtils.matchNumber(StringUtils.substringBefore(commTxt, "阅读"));
			commnetNum = NumberUtils.matchNumber(StringUtils.substringBefore(commTxt, "回复"));
		}
		if (clickNum == null && commnetNum==null ){
			commTxt = doc.select("span.hm").text();
			clickNum = NumberUtils.matchNumber(StringUtils.substringBefore(commTxt, "阅读"));
			commnetNum = NumberUtils.matchNumber(StringUtils.substringAfter(commTxt, "阅读"));
		}
		if (clickNum == null && commnetNum==null ){
			commTxt = doc.select("td.pls:contains(回复)").text();
			clickNum = NumberUtils.matchNumber(StringUtils.substringAfter(commTxt, "查看"));
			commnetNum = NumberUtils.matchNumber(StringUtils.substringAfter(commTxt, "回复"));
		}
		if (clickNum == null && commnetNum==null ){
			commTxt = doc.select(":containsOwn(查看:)").text();
			clickNum = NumberUtils.matchNumber(StringUtils.substringAfter(commTxt, "查看:"));
			commnetNum = NumberUtils.matchNumber(StringUtils.substringAfter(commTxt, "回复:"));
		}
		if (clickNum == null && commnetNum==null ){
			commTxt = doc.select(".comiis_vbg").text();
			clickNum = NumberUtils.matchNumber(StringUtils.substringBetween(commTxt, "阅读[","]"));
			commnetNum = NumberUtils.matchNumber(StringUtils.substringAfter(commTxt, "回复["));
		}
		if (clickNum == null && commnetNum==null ){
			commTxt = doc.select("div.yd").text();
			clickNum = NumberUtils.matchNumber(StringUtils.substringBefore(commTxt, "查看"));
			commnetNum = NumberUtils.matchNumber(StringUtils.substringAfter(commTxt, "查看"));
		}

		if (clickNum == null && commnetNum==null ){
			clickNum = NumberUtils.matchNumber(doc.select("span.comiis_cks").text());
			commnetNum = NumberUtils.matchNumber(doc.select("span.comiis_hfs").text());
		}
		if (clickNum == null && commnetNum==null ){
			String text = doc.select("div.cont-hd p span em.s1").text();
			clickNum = NumberUtils.matchNumber(StringUtils.substringBefore(text, " "));
			commnetNum = NumberUtils.matchNumber(StringUtils.substringAfter(text, " "));
		}

		if(clickNum==null && commnetNum==null){
			 Elements select = doc.select("div.subject > .xi1");
			 if(select.size()==2){
				 clickNum=NumberUtils.matchNumber(select.get(0).text());
				 commnetNum=NumberUtils.matchNumber(select.get(1).text());
			 }
		}
		if(clickNum==null ||commnetNum==null){
			 Elements select = doc.select("span.xi1");
			 if(select.size()==2){
				 clickNum=NumberUtils.matchNumber(select.get(0).text());
				 commnetNum=NumberUtils.matchNumber(select.get(1).text());
			 }
		}
		if(StringUtils.isBlank(author)){
			author=doc.select(".poster").text();
		}
		if(StringUtils.isBlank(author)){
			Element first = doc.select("div.authi a.xw1").first();
			if (first!=null){
        		author=first.text();
        	}
		}
        if(StringUtils.isBlank(author)){
        	Element first = doc.select(".eduu_thread_ifo a.xw1").first();
        	if (first!=null){
        		author=first.text();
        	}
        }
        if(StringUtils.isBlank(author)){
        	try {
        		author=doc.select("cite").first().text();
        	} catch (Exception e) {
        	}
        }
        if(StringUtils.isBlank(author)){
        	try {
        		author=doc.select("div.readName").first().text();
        	} catch (Exception e) {
        	}
        }
        if(StringUtils.isBlank(author)){
        	try {
        		author=doc.select("div.side div.r_name.cc.mb5 a.fb").first().text();
        	} catch (Exception e) {
        	}
        }
        if(StringUtils.isBlank(author)){
        	try {
    			author=doc.select(".postinfo a[href^=space.php?uid=]").first().text();
			} catch (Exception e) {
			}
			if(StringUtils.isBlank(author)){
				try {
					author = doc.select("div.mn div.bm div.h p.xg1 a").first().text();
				} catch (Exception e) {
				}
			}
		}
        if(StringUtils.isBlank(author)){
        	try {
        		author = doc.select("td.t_user a[href^=space-uid-]").first().text();
        	} catch (Exception e) {
        	}
        }
        if(StringUtils.isBlank(author)){
        	author = doc.select("a.nickname").text();
        }
        if(StringUtils.isBlank(author)){
        	Elements authorList = doc.select("b.fl");
        	if(authorList.size()>0)
        	{
        		author = authorList.get(0).text();
        	}
        }
        if(StringUtils.isBlank(author)){
        	Elements authorList = doc.select("p.name a");
        	if(authorList.size()>0)
        	{
        		author = authorList.get(0).text();
        	}
        }
        if(StringUtils.isBlank(author)){
        	Elements authorList = doc.select("a.name");
        	if(authorList.size()>0)
        	{
        		author = authorList.get(0).text();
        	}
        }
        if(StringUtils.isBlank(author)){
        	Elements authorList = doc.select("table.viewthread a.bold");
        	if(authorList.size()>0)
        	{
        		author = authorList.get(0).text();
        	}
        }
        if(StringUtils.isBlank(author)){
        	Elements authorList = doc.select(".r_name a[href]");
        	if(authorList.size()>0)
        	{
        		author = authorList.get(0).text();
        	}
        }


		news.setUrl(url);
		news.setAuthor(author);
		news.setTitle(StringUtils.trimSpace(title));
		news.setCommentNum(commnetNum);
		news.setClickNum(clickNum);
		news.setContent(StringUtils.trimSpace(content));
		news.setDate(date);
		news.setUpdateUrl(updateUrl);
		return news;

	}
	public NewsMeta Update(NewsMeta meta) {
		String url = meta.getUpdateUrl();
		if (StringUtils.isNotBlank(url)){
			UrlMeta urlMeta = CrawlHTML.responseToURL(url);
			return parserHtml(urlMeta);
		}
		return null;
	}

	public boolean isNeedUpdate() {
		return true;
	}
//	
//	static final String SPECIAL_FLAG_REGX="[\\-+=_)(*&\\^%$#@!~/\\?<>,;:'\"`\\*\\\\\\[\\]\\[{\\}\\|！￥ （），�?�？：；“�?��?��?? ＊�?��?�｛｝＼、�?��?�～ ＠＃ ％＆×  —�?�＋－＝｜�?��?�]";
//	public static void toIndex(AbstractMeta meta,UrlMeta urlMeta,int entryId) throws Exception{
//		/**
//		 * 初始化建索引连接
//		 */
//		RPCClient<IndexCreateTaskQueueInterface> rpcClientCreateIndex = new RPCClient<IndexCreateTaskQueueInterface>(IndexCreateTaskQueueInterface.class, "113.107.235.102", 9999);
//		@SuppressWarnings("unused")
//		IndexCreateTaskQueueInterface CreateIndexTaskQueueClient = rpcClientCreateIndex.getClient();
//		IndexMeta analysedMeta=null;
//		if (meta!=null && StringUtils.isNotBlank(meta.getTitle()) && meta.getDate()!=null){
//			meta.setUrl(urlMeta.getUrl());
//			analysedMeta=MetaConvertUtils.convertToSaveMeta(meta);
//			analysedMeta.setEntryId(entryId);
//			/**
//			 * SaveMeta实体 添加 主题关键字列�?
//			 */
////			List<Keyword> getDocumentTopicKeyWord = TopicKeyword.GetDocumentTopicKeyWord(analysedMeta.getTitle(), analysedMeta.getContent());
////			analysedMeta.setKeywordMetaConvert(getDocumentTopicKeyWord);
//		}
//		if(analysedMeta!=null){
//			String title = analysedMeta.getTitle();
//			title =  title.replaceAll(SPECIAL_FLAG_REGX," ");
//			if(title.indexOf("新手报到")!=-1 ||title.indexOf("新手报道")!=-1 || title.indexOf("新人报到")!=-1 || title.indexOf("新人报道")!=-1
//					|| title.indexOf("新人来报�?")!=-1 || title.indexOf("招聘兼职")!=-1 || title.equals("贴吧404")){
//				return;
//			}
//			/**
//			 * 计算文档的正负属�? 以及simHash
//			 */
//			try {
//				TextAnalysisUtils.AnalysisData(analysedMeta);
//			} catch (Exception e) {
//				// TODO Auto-generated catch block
//				System.out.println("【计算文本正�?,simHash异常�?:" + urlMeta.getUrl()+"\n"+e);
//			}
//			/**
//			 * 保存解析的数�?
//			 */
//			analysedMeta.setHtmlBytes(urlMeta.getHtmlBytes());
//			/**
//			 * 添加到索引服务器
//			 */
//			Long date = analysedMeta.getDate();
//			//只有�?年内的信息才�?要建索引，解析出错导致时间穿越的也不建索�?
//			long currentTimeMillis = System.currentTimeMillis();
//			Long startDate = currentTimeMillis-1000l*60*60*24*365;
////			long dateBetweenToday = ( (System.currentTimeMillis() - date)/1000/60/60/24) ;
//			if (date!=null && date>startDate && date<currentTimeMillis){
//				String author = analysedMeta.getAuthor();
//				if(StringUtils.isNotBlank(author)&&author.length()>20){
//					analysedMeta.setAuthor(null);
//				}
//
//				@SuppressWarnings("unused")
//				byte[] dataBytes=StringUtils.ZipObject(analysedMeta);
//				System.out.println(analysedMeta.getTitle()+","+analysedMeta.getEntryId()+","+analysedMeta.getUrl());
////				CreateIndexTaskQueueClient.AddCreateIndexTask(dataBytes);
//				System.out.println(" 保存�?" + Constants.getTypeDesc(analysedMeta.getType() ) + "�?:" + analysedMeta.getUrl());
//			}
//		}
//	}
//	public static void main(String[] args) throws Exception {
//		BbsAnalyseDiscuz a = new BbsAnalyseDiscuz();
//		String url = "http://www.r021.com/forum.php?extra=page%3D1%26filter%3Dauthor%26orderby%3Ddateline&mod=viewthread&page=2&tid=349763";
//		System.out.println(DoMainUtils.GetDomainName(url));
////		url = UrlArgumentTop.FromatUrl(url);
//		System.err.println(UrlArgumentTop.FromatUrl(url));
//		System.out.println(a.isDetailPage(url));
//		UrlMeta meta = CrawlHTML.responseToURL(url);
//
//		NewsMeta parserHtml = a.parserHtml(meta);
//		System.out.println(parserHtml);
//		meta.setUrl(url);
//
////		toIndex(parserHtml, meta, 2062470);
////		System.out.println(AnalyseMap.getInstance().parserHtml(meta,3));
//
//	}
	
}
